<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var minSetSize = function (arr) {
      let n = arr.length, map = new Map()
      for (let a of arr) {
        map.set(a, (map.get(a) || 0) + 1)
      }
      n >>= 1
      let vs = [...map.values()].sort((a, b) => b - a), sum = 0, c = 0, index = 0
      while (sum < n) {
        sum += vs[index++]
        c++
      }
      return c
    };
    console.log(minSetSize([3, 3, 3, 3, 5, 5, 5, 2, 2, 7]));
  </script>
</body>

</html>